package api

import (
	"api/global"
	__ "api/proto"
	"api/request"
	"github.com/gin-gonic/gin"
	"net/http"
)

func ShopAdd(c *gin.Context) {

	var form request.Shop
	if err := c.ShouldBind(&form); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}
	add, err := global.AddClient.ShopAdd(c, &__.ShopAddReq{
		Name:   form.Name,
		Price:  form.Price,
		Number: int64(form.Number),
		UserId: int64(form.UserId),
	})
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"message": "发布失败：" + err.Error(),
			"code":    "500",
			"data":    nil,
		})
		return
	}

	c.JSON(http.StatusOK, gin.H{
		"message": "发布成功",
		"code":    "200",
		"data":    add.ShopId,
	})
}
